var express = require('express');
var query = require('./db');
var prosRouter = express.Router();

prosRouter.get('/getpros', function (req, res, next) {
    query(`select * from products where category_id='${req.query.cateid}' LIMIT ${req.query.pagesize}`, function (err, result) {
        let obj={
            status:200,
            data:result
        }
        if(err){
            status=0;
            data=err;
            res.send(obj);
        }
        else{
            res.send(obj);
        }
    });
});

prosRouter.get('/getProInfo',function(req,res,next){
  query(`select * from products where pid=${req.query.pid}`,function(err,result){
    let obj={
        status:200,
        data:result
    }
    if(err){
        status=0;
        data=err;
        res.send(obj);
    }
    else{
        res.send(obj);
    }
  });
});


module.exports = prosRouter;